<template>
  <el-dialog title="绑定车辆" width="30%" :visible.sync="show" @close="dialogClose">
    <el-form ref="form" :model="form" label-width="120px" style="margin-right:80px">
      <el-form-item label="驾驶员">
        <label>{{ form.realName }}</label>
      </el-form-item>
      <el-form-item label="车辆" prop="carId" :rules="rules.def">
        <form-remote-select
          v-model="form.carId"
          :url="$http.conf.api.get('wms').url+'/api/logistics/car/map/0'"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button v-loading="modal_loading" type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      show: false,
      form: {
        realName: '',
        driverId: '',
        carId: ''
      },
      modal_loading: false,
      rules: this.$ruleStore.rules
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
    },
    bind(row) {
      this.show = true
      // alert(this.show)
      this.form.realName = row.realName
      this.form.driverId = row.id
    },
    submit() {
      const that = this
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.modal_loading = true
          const url = that.$http.conf.api.get('wms').url + '/api/logistics/driver/bind'
          console.log(url)
          that.$http.post(url, that.form).then(function(rsp) {
            that.modal_loading = false
            if (rsp.code !== 200) {
              that.$message.error(rsp.message)
              return
            }
            that.$message.success('操作成功!')
            that.show = false
            that.$emit('bindQuery', that.form)
          }).catch(function(err) {
            that.modal_loading = false
            console.log(err)
          })
        } else {
          // this.$Message.error('Fail!');
        }
      })
    },
    // 清空默认值
    dialogClose() {
      this.form.carId = ''
    }
  }
}
</script>
